package com.lianxian.xindong.commonres.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.hxb.library.base.BaseFragment;
import com.hxb.library.widget.SYHFragmentAdapter;
import com.lianxian.xindong.commonres.R;
import com.lianxian.xindong.commonres.weight.ImgeFragment;

import java.util.ArrayList;
import java.util.List;

public class FullImageActivity extends AppCompatActivity {

    private ViewPager vp_pictrue;
    private int curentPosion;
    private ArrayList<String> data;
    private TextView tv_bottom;
    private List<BaseFragment> fragmentList = new ArrayList<>();
    private RelativeLayout full_lay;
    private boolean isShow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_full_image);
        data = getIntent().getStringArrayListExtra("data");
        curentPosion = getIntent().getIntExtra("curentPosion", 0);
        isShow = getIntent().getBooleanExtra("isShow", false);
        initViewPager( );

    }

    private void initViewPager() {

        full_lay = (RelativeLayout) findViewById(R.id.full_lay);
        vp_pictrue = (ViewPager) findViewById(R.id.vp_pictrue);
        tv_bottom = (TextView) findViewById(R.id.tv_bottom);

        if (isShow){
            tv_bottom.setVisibility(View.VISIBLE);
        }else {
            tv_bottom.setVisibility(View.GONE);
        }

        tv_bottom.setText((curentPosion+1)+"/"+data.size());

        for (int i=0;i<data.size();i++){
            ImgeFragment imgeFragment = new ImgeFragment();
            Bundle bundle = new Bundle();
            bundle.putString("imgUrl",data.get(i));
            imgeFragment.setArguments(bundle);
            fragmentList.add(imgeFragment);
        }

        vp_pictrue.setOffscreenPageLimit(fragmentList.size());
        vp_pictrue.setAdapter(new SYHFragmentAdapter(getSupportFragmentManager(), fragmentList));
        vp_pictrue.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageScrolled(int i, float v, int i1) {
            }

            @Override
            public void onPageSelected(int i) {
                tv_bottom.setText((i+1)+"/"+data.size());
            }
            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });

        vp_pictrue.setCurrentItem(curentPosion);

    }


    @Override
    public void onBackPressed() {
        finish();
        overridePendingTransition(0, 0);
    }



}
